package com.bsi.rd.framework.zuul.filter;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.filter.CorsFilter;

/**
 * DESCRIPTION:
 *
 * @author zouyan
 * @create 2018/9/30-下午5:05
 * created by fuck~
 **/
@Configuration
@EnableAutoConfiguration
public class FilterConfig {

    @Autowired
    private HeaderFilter headerFilter;

    @Autowired
    private CorsFilter corsFilter;

    @Autowired
    private ParamsFilter paramsFilter;

    @Bean
    public FilterRegistrationBean filterRegistrationBean() {
        FilterRegistrationBean registrationBean = new FilterRegistrationBean();
        registrationBean.setFilter(headerFilter);
        registrationBean.setOrder(1);
        return registrationBean;
    }

    @Bean
    public FilterRegistrationBean filterRegistrationCorsBean() {
        FilterRegistrationBean registrationBean = new FilterRegistrationBean();
        registrationBean.setFilter(corsFilter);
        registrationBean.setOrder(-1);
        return registrationBean;
    }

    @Bean
    public FilterRegistrationBean filterRegistrationParamsBean() {
        FilterRegistrationBean registrationBean = new FilterRegistrationBean();
        registrationBean.setFilter(paramsFilter);
        registrationBean.setOrder(Integer.MAX_VALUE-1);
        return registrationBean;
    }

    @Bean
    public HeaderFilter headerEnhanceFilter() {
        return new HeaderFilter();
    }

    @Bean
    public ErrorFilter errorFilter(){
        return  new ErrorFilter();
    }

    @Bean
    public ParamsFilter paramsFilter(){
        return  new ParamsFilter();
    }

}
